﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QldtSdh.BLL;
using QldtSdh.DAL.Models;
using QldtSdh.GUI.Common;
using QldtSdh.GUI.Utils;
namespace QldtSdh.GUI.DaoTao
{
    public partial class FormThongKeGioGiang : BaseForm
    {
        HocKy hocKy = null;
        bool allowUpdate = false;
        public FormThongKeGioGiang(HocKy hocKy)
        {
            InitializeComponent();
            this.hocKy = hocKy;
            gridData.AddRowIndexing();
            gridData.AutoGenerateColumns = false;
            LoadDonViPhuTrach();

        }
        void LoadDonViPhuTrach()
        {
            allowUpdate = false;
            var ls = BizDonViDaoTao.GetList();
            cmbDonViPhuTrach.DataSource = ls;
            cmbDonViPhuTrach.DisplayMember = "TenDonVi";
            cmbDonViPhuTrach.ValueMember = "MaDonViGUID";
            LoadGiangVien();
        }
        void LoadGiangVien()
        {
            btnThongKe.Enabled = false;
            cmbGiangVien.DataSource = null;
            if (cmbDonViPhuTrach.SelectedIndex != -1)
            {
                var ls = BizGiangVien.GetList(cmbDonViPhuTrach.SelectedValue.ToString());
                cmbGiangVien.DataSource = ls;
                cmbGiangVien.DisplayMember = "_TenDayDu";
                cmbGiangVien.ValueMember = "MaGiangVien";
                if (ls != null && ls.Count > 0)
                    btnThongKe.Enabled = true;
            }
            allowUpdate = true;
        }

        private void btnThongKe_Click(object sender, EventArgs e)
        {
            bdData.DataSource = null;
            btnIn.Enabled = false;
            lblTongSoGioGiangDay.Text = "0 giờ";
            var giangVien = cmbGiangVien.SelectedItem as GiangVien;
            if (giangVien != null)
            {
                var ls = BizPhanCongGiangDay.ThongKeGioGiang(hocKy, giangVien.MaGiangVien);
                bdData.DataSource = ls;
                if (ls != null && ls.Count > 0)
                {
                    btnIn.Enabled = true;
                    lblTongSoGioGiangDay.Text = ls.Sum(t => t.SoGioDamNhan).ToString() + " giờ";
                }
            }
            gridData.DataSource = bdData;
        }

        private void btnIn_Click(object sender, EventArgs e)
        {

        }
        private void cmbDonViPhuTrach_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (allowUpdate)
                LoadGiangVien();
        }
    }
}
